<?php
require_once "class_Main.php";

	class Login extends Main{
	
		protected $login_conn;

		public function __construct(){
			$this->login_conn = parent::connect();
		}
		
		private function dataChk ($login, $pass){
			$sel = "SELECT pass FROM auth WHERE login = '$login' ";
			$result = mysql_query ($sel, $this -> login_conn);	
			$fetch = mysql_fetch_row ($result);
			if ($fetch[0] == "") return false;																	
			return $fetch [0] === $pass;
			mysql_close ($this -> login_conn);
		}

		public function login ($login, $pass){
			$pass = md5($pass);
			if ($this -> dataChk($login, $pass)){
				session_start ();
				$_SESSION ["login"] = $login;
				$_SESSION ["pass"] = $pass;
				return true;
			}
			else { return false; }
		}
		
		public function isAuth (){
	//			session_start ();
					if (isset($_SESSION ["login"])){
						$login = $_SESSION ["login"];
						$pass = $_SESSION ["pass"];
						return $this -> dataChk ($login, $pass);		
					}
					else {return false;}
		}
/*
		public function __destruct (){
			$this ->__destruct();
			//parent::main_close();
			echo "child destruct";
		}*/
	}
?>